<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php $this->load->view('include/html_head')?>
</head>
<body>
<div id="wrapper">
	<?php $this->load->view('include/header')?>
	<?php $this->load->view('include/menu')?>
	<div id="page">
		<div id="content">
		<?php $this->load->view('include/sub_navi')?>
			<div class="post">
			<form action="<?php echo BACKEND_ASSOCIATION_NEWS_EDIT_POST_PATH ?>" id='edit_form' class='' method='post'>
				<p class="meta">新闻管理</p>
				<div class="entry">
				<input type='hidden' id="id" name="id" value="<?php echo set_value('id', $news['id'])?>"/>
				<input type='hidden' id="is_published" name="is_published" value="<?php echo set_value('is_published', $news['is_published'])?>"/>
			    	<table class='full'>
				        <tbody>
						  	<tr>
						  	<th>标题</th>
						  	<td>
						  	<input type="text" id='title' name='title' class="validate[required,minSize[2],maxSize[20]] text-input"  value="<?php echo set_value('title', $news['title'])?>" />
						  	<?php echo form_error('title', '<div class="error">', '</div>'); ?>
						  	</td>
						  	
					  		</tr>
					  	
						  	<tr>
							<th>简介</th>
					  		<td><textarea id='description' name='description' class="validate[required,minSize[2],maxSize[50]] text-input"><?php echo set_value('description', $news['description'])?></textarea>
						  	<?php echo form_error('description', '<div class="error">', '</div>'); ?>
						  	</td>
					  		</tr>
					  		
					  		<tr>
					  		<th>作者</th>
							<td>
							<?php if ($news['id'] != "") :?>
							<?php echo $news['poster_name']?>
						  	<?php else :?>
						  	<script>
							//给下拉菜单绑值
							$(function() {
								$('#poster_id option').each(function() {
									if($(this).val() == <?php echo $news['poster_id'] + "" ?>) {
										$(this).attr("selected", "selected");
									}
								});
							});
							</script>
					  		<select id="poster_id" name="poster_id" class="validate[required]">
					  			<option value="">请选择</option>
								<?php foreach ($news['temp_poster_array'] as $k => $v):?>
								<option value="<?php echo $v['employee_id']?>" ><?php echo $v['a_name']?></option>
								<?php endforeach;?>
						  	</select>
						  	<?php echo form_error('poster_id', '<div class="error">', '</div>'); ?>
						  	<?php endif;?>
						  	</td>
					  		</tr>
					  	</tbody>
				  	</table>
				  	
					<textarea id='contents' cols="90" name='contents' class="validate[required,minSize[50],maxSize[10000]] text-field"><?php echo set_value('contents', $news['contents'])?></textarea>
			  		<?php echo form_error('contents', '<div class="error">', '</div>'); ?>
			  		<script type="text/javascript">
			        	var contents_editor = CKEDITOR.replace('contents', { toolbar : 'NewsToolbar', height : 400 });
			        	CKFinder.setupCKEditor(contents_editor, '<?php echo PLUGIN_CKFINDER_FOLDER ?>');
			        	
			        	contents_editor.on("instanceReady", function(){
							//set keyup event
							this.document.on("keyup", updateTextArea);
							//and paste event
							this.document.on("paste", updateTextArea);
							
							this.document.on("blur", check);
						});
						
						function updateTextArea() {
							CKEDITOR.instances.contents.updateElement(); 
						}
						
						function check() {
							$("#contents").focus();
							$("#contents").blur();
						}        	
			    	</script>
					
					<script>
					$("button#post").live('click', function() {
						$("#is_published").val(<?php echo IS_PUBLISHED ?>);
					});
					$("button#save").live('click', function() {
						$("#is_published").val(<?php echo NOT_PUBLISHED ?>);
					});
					</script>
					<?php if ($news['id'] == '') :?>
					<button type='submit' id='post' >发布</button>
					<button type='submit' id='save' >保存</button>
				    <?php elseif ($news['is_published'] == NOT_PUBLISHED):?>
				    <a class='anchor_button' id='post' href="<?php echo BACKEND_ASSOCIATION_NEWS_PUBLISH_PATH . $news['id']?>" >发布</a>
					<button type='submit' id='save' >保存</button>
					<?php elseif ($news['is_published'] == IS_PUBLISHED):?>
					<button id='post' type='submit' >保存</button>
					<?php endif;?>
					<a class='anchor_button' onclick="history.back(-1);" >返回</a>
				</div>
			</form>
			</div>
			<div style="clear: both;">&nbsp;</div>
		</div>
		<!-- end #content -->
		<?php $this->load->view('include/side_bar')?>
		<div style="clear: both;">&nbsp;</div>
	</div>
	<!-- end #page -->
</div>
<?php $this->load->view('include/footer_content')?>
<?php $this->load->view('include/footer')?>
</body>
</html>
